subroutine writeToFileDouble(nfile,solution,n)
    dimension solution(n)
    real*8 solution
    do i=1,n
        write(nFile,rec=i) solution (i)
    enddo
end
!*************************************************************************
subroutine writeToFileInteger(nfile,solution,n)
    dimension solution(n)
    integer solution
    do i=1,n
        write(nFile,rec=i) solution (i)
    enddo
end
!*************************************************************************
subroutine readFromFileDouble(nfile,solution,n)
    dimension solution(n)
    real*8 solution
    do i=1,n
        read(nFile,rec=i) solution (i)
    enddo
end
!*************************************************************************
subroutine readFromFileInteger(nfile,solution,n)
    dimension solution(n)
    integer solution
    do i=1,n
        read(nFile,rec=i) solution (i)
    enddo
end
!*************************************************************************
subroutine readMatrixT(ig_dat,jg_dat,gg_dat,igT,jgT,ggT,nodesTermCount,mTerm)
    dimension igT(nodesTermCount+1),jgT(*),ggT(*)
    real*8 ggT
    integer gg_dat

    do j=1,nodesTermCount+1
        read(ig_dat,rec=j)igT(j)
    enddo
    mTerm=igT(nodesTermCount+1)-1

    do j=1,mTerm
        read(jg_dat,rec=j)jgT(j)
        read(gg_dat,rec=j)ggT(j)
    enddo
end
!*************************************************************************
subroutine readNumberVertex2D(nFile,nVertex,elemsCount)
    integer elemsCount
    dimension nVertex(4,elemsCount)
    do j=1,elemsCount
        read(nFile,rec=j)nVertex(3,j),nVertex(4,j),&
                         nVertex(1,j),nVertex(2,j),k,k
    enddo
end
!*************************************************************************
subroutine readNumberVertex3D(nFile,nVertex,elemsCount)
    integer elemsCount
    dimension nVertex(14,elemsCount)
    do j=1,elemsCount
        read(nFile,rec=j)(nVertex(k,j),k=1,14)
    enddo
end
!*************************************************************************
subroutine readVertexAndGetBound2D(nFile,vertex,nodesCount,minR,maxR,minZ,maxZ)
    dimension vertex(2,nodesCount)
    real*8 vertex,minR,maxR,minZ,maxZ
    read(nFile,rec=1)vertex(1,1),vertex(2,1)
    maxR=vertex(1,1)
    maxZ=vertex(2,1)
    minR=vertex(1,1)
    minZ=vertex(2,1)
    do j=2,nodesCount
        read(nFile,rec=j)vertex(1,j),vertex(2,j)
        if(vertex(1,j).gt.maxR)maxR=vertex(1,j)
        if(vertex(1,j).lt.minR)minR=vertex(1,j)
        if(vertex(2,j).gt.maxZ)maxZ=vertex(2,j)
        if(vertex(2,j).lt.minZ)minZ=vertex(2,j)
    enddo
end
!*************************************************************************
subroutine readVertexAndGetBound3D(nFile,vertex,nodesCount,minX,maxX,minY,&
maxY,minZ,maxZ)
    real*8 vertex,minX,maxX,minY,maxY,minZ,maxZ
    dimension vertex(3,nodesCount)

    read(nFile,rec=1)vertex(1,1),vertex(2,1),vertex(3,1)
    maxX=vertex(1,1)
    maxY=vertex(2,1)
    maxZ=vertex(3,1)
    minX=vertex(1,1)
    minY=vertex(2,1)
    minZ=vertex(3,1)
    do j=2,nodesCount
        read(nFile,rec=j)vertex(1,j),vertex(2,j),vertex(3,j)
        if(vertex(1,j).gt.maxX)maxX=vertex(1,j)
        if(vertex(1,j).lt.minX)minX=vertex(1,j)
        if(vertex(2,j).gt.maxY)maxY=vertex(2,j)
        if(vertex(2,j).lt.minY)minY=vertex(2,j)
        if(vertex(3,j).gt.maxZ)maxZ=vertex(3,j)
        if(vertex(3,j).lt.minZ)minZ=vertex(3,j)
    enddo
end
!*************************************************************************
subroutine readVertex(nFile,vertex,nodesCount,dim)
    real*8 vertex
    integer dim
    dimension vertex(dim,nodesCount)
    do j=1,nodesCount
        read(nFile,rec=j)(vertex(k,j),k=1,dim)
    enddo
end
!*************************************************************************
subroutine readPoints(nFile,points,nPoints)
    dimension points(3,nPoints)
    real*8 points
    do j=1,nPoints
        read(nFile,*)points(1,j),points(2,j),points(3,j)
    enddo
end
!*************************************************************************
subroutine readMN(nFile,MN,nMN)
    dimension MN(6,nMN)
    real*8 MN
    do j=1,nMn
        read(nFile,*)MN(1,j),MN(2,j),MN(3,j),MN(4,j),MN(5,j),MN(6,j)
    enddo
end
!*************************************************************************
subroutine readAreaProperties(nFile,alp,T0,num,nAreas)
    dimension alp(nAreas),T0(nAreas),num(nAreas)
    real*8 alp,T0
    do i=1,nAreas
        read(nFile,*) num(i),alp(i),T0(i)
    enddo
end
!*************************************************************************
subroutine readNodesForEdges(nodesforedges_dat,edges_dat,nodesforedges,&
    edgesCount,elemsCount)
    integer edges_dat,edgesCount,elemsCount,edges
    dimension nodesforedges(3,edgesCount),edges(12)

    do j=1,edgesCount
        read(nodesforedges_dat,rec=j) nodesforedges(1,j),nodesforedges(2,j)
    enddo

    do j=1,elemsCount
        read(edges_dat,rec=j) (edges(k),k=1,12),l,l,l,l,l,l,l,l,l,l,l,l,l
        do k=1,12
            nodesforedges(3,edges(k))=j
        enddo
    enddo 
end
!*************************************************************************
subroutine readMesh2D(rz_dat,nvkat2D_dat,nvtr_dat,l1_dat,vertex,nInCat,nVer,&
    l1,nodesCount,elemsCount,nodesBoundCount,minR,maxR,minZ,maxZ)
    integer rz_dat,nvkat2D_dat,nvtr_dat,elemsCount,l1_dat
    real*8 vertex,minR,maxR,minZ,maxZ
    dimension vertex(2,nodesCount),nInCat(elemsCount),nVer(4,elemsCount),&
    l1(nodesBoundCount)

    if(rz_dat.ne.0)call readVertexAndGetBound2D(rz_dat,vertex,nodesCount,minR,maxR,minZ,maxZ)
    if(nvkat2D_dat.ne.0)call readFromFileInteger(nvkat2D_dat,nInCat,elemsCount)
    if(nvtr_dat.ne.0)call readNumberVertex2D(nvtr_dat,nVer,elemsCount)
    if(l1_dat.ne.0)call readFromFileInteger(l1_dat,l1,nodesBoundCount)
end
!*************************************************************************
subroutine readMesh3D(xyz_dat,nvkat_dat,nver_dat,l1_dat,nodesforedges_dat,&
    edges_dat,vertex,nInCat,nVer,l1,nodesforedges,nodesCount,elemsCount,&
    edgesCount,nodesBoundCount,minX,maxX,minY,maxY,minZ,maxZ)
    integer xyz_dat,nvkat_dat,nver_dat,l1_dat,nodesforedges_dat,edges_dat,elemsCount,edgesCount
    real*8 vertex,minX,maxX,minY,maxY,minZ,maxZ
    dimension vertex(3,nodesCount),nVer(14,elemsCount),nInCat(elemsCount),&
    l1(nodesBoundCount),nodesforedges(3,edgesCount)

    if(xyz_dat.ne.0)call readVertexAndGetBound3D(xyz_dat,vertex,nodesCount,minX,maxX,minY,maxY,minZ,maxZ)
    if(nvkat_dat.ne.0)call readFromFileInteger(nvkat_dat,nInCat,elemsCount)
    if(nver_dat.ne.0)call readNumberVertex3D(nver_dat,nVer,elemsCount)    
    if(l1_dat.ne.0)call readFromFileInteger(l1_dat,l1,nodesBoundCount)
    if(nodesforedges_dat.ne.0.and.edges_dat.ne.0)then
        call readNodesForEdges(nodesforedges_dat,edges_dat,nodesforedges,&
        edgesCount,elemsCount)
    endif
end
!*************************************************************************
subroutine readMediaInfo(media_txt,zLayers,xObjects,yObjects,zObjects,&
    numbersObjects,nLayers,nObjects,nXObjects,nYObjects,nZObjects,&
    sigmaLayers,sigmaObjects,alp_layers,T0_layers,alp_objects,T0_objects)
    real*8 zLayers,xObjects,yObjects,zObjects,sigmaLayers,sigmaObjects,&
    alp_layers,T0_layers,alp_objects,T0_objects
    character*20 text
    dimension zLayers(nLayers),xObjects(nXObjects),yObjects(nYObjects),&
    zObjects(nZObjects),numbersObjects(6,nObjects),sigmaLayers(nLayers),&
    sigmaObjects(nObjects),alp_layers(nLayers),T0_layers(nLayers),&
    alp_objects(nObjects),T0_objects(nObjects)

    read(media_txt,*) text
    do j=1,nLayers
        read(media_txt,*)zLayers(j),sigmaLayers(j),alp_layers(j),T0_layers(j)
    enddo

    read(media_txt,*) text
    do j=1,nXObjects
        read(media_txt,*)xObjects(j)
    enddo

    read(media_txt,*) text
    do j=1,nYObjects
        read(media_txt,*)yObjects(j)
    enddo
    
    read(media_txt,*) text
    do j=1,nZObjects
        read(media_txt,*)zObjects(j)
    enddo

    read(media_txt,*) text
    do j=1,nObjects
        read(media_txt,*)sigmaObjects(j),alp_objects(j),T0_objects(j),&
                        (numbersObjects(k,j),k=1,6)
    enddo
end
!*************************************************************************
!*************************************************************************
!*************************************************************************